package com.wms.helper;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

/**
 * Provides dialogs for a variety of messages.
 * @author Nathan
 */
public class DialogFactory {
	private AlertDialog.Builder dFactory;
	
	/**
	 * Creates a new class with the given context
	 * @param context - the context to be used for creating new dialogs
	 */
	public DialogFactory (Context context) {
		dFactory = new AlertDialog.Builder(context);
	}
	
	/**
	 * Brings up an alert dialog with an OK button, and customizable text and title
	 * @param message - the text to display in alert body
	 * @param title - the text to display at the top of the alert
	 * @return a new @see AlertDialog instance
	 */
	public AlertDialog alertOK(String message, String title) {
		dFactory.setNeutralButton("OK", new DialogFactory.CloseListener());
		AlertDialog alert = dFactory.create();
		alert.setTitle(title);
		alert.setMessage(message);
		return alert;
	}

	/**
	 * An event handler that closes dialogs
	 * @author Nathan
	 *
	 */
	private class CloseListener implements DialogInterface.OnClickListener {
		@Override
		public void onClick(DialogInterface dialog, int which) {
			dialog.dismiss();
		}
	}
}
